package com.cntcdt.api.db.dao;

import java.util.List;

import com.cntcdt.api.db.dao.base.GroupDeviceDaoBase;
import com.cntcdt.api.db.model.GroupDeviceModel;

/**
 * 这是cdt_group_device的Dao实现类
 */
public class GroupDeviceDao extends GroupDeviceDaoBase   {
    /**
     * GroupDeviceDao对象
     */
    private static GroupDeviceDao instance = new GroupDeviceDao();

    /**
     * 默认构造方法
     */
    private GroupDeviceDao() {
    }

    /**
     * 获得对象实例
     */
    public static GroupDeviceDao getInstance() { 
         return instance;
    } 
    
    /**
     * 按查询model
     * @param id id
     * @return model
     */
    public List<GroupDeviceModel> findByGroupId(int groupId) {
        String sql = "SELECT * FROM " + TABLE + " WHERE groupId = ? and opStatus = 0";
       Object[] paramObjs = {groupId};
       List<GroupDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       return  modelList;
   }
    
    /**
     * 按查询model
     * @param id id
     * @return model
     */
    public GroupDeviceModel findByGroupIdAndTerminal(int groupId,String terminal) {
        String sql = "SELECT * FROM " + TABLE + " WHERE groupId = ? and terminal = ? and opStatus = 0";
       Object[] paramObjs = {groupId,terminal};
       List<GroupDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       if(modelList.size() > 0){
    	   return modelList.get(0);
       }
       return  null;
   }
    
    /**
     * 按查询model
     * @param id id
     * @return model
     */
    public GroupDeviceModel findByTerminal(String terminal) {
        String sql = "SELECT * FROM " + TABLE + " WHERE terminal = ?";
       Object[] paramObjs = {terminal};
       List<GroupDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       if(modelList.size() > 0){
    	   return modelList.get(0);
       }
       return  null;
   }
    
    public List<GroupDeviceModel> findBySearchContent(String searchContent,long sortTime) {
    	sortTime = sortTime*20;
        String sql = "SELECT * FROM " + TABLE + " WHERE terminal like ? and opStatus = 0 limit ?,20";
       Object[] paramObjs = {searchContent,sortTime};
       List<GroupDeviceModel > modelList = this.queryModelList(sql, paramObjs);
       return  modelList;
   }    
    
    /**
     * 查询机器model
     * @param terminal
     * @return
     */
	public GroupDeviceModel findByTerminalIsRepeat(String terminal) {
		String sql = "SELECT * FROM " + TABLE + " WHERE terminal = ? and opStatus = 0";
		Object[] paramObjs = { terminal };
		List<GroupDeviceModel> modelList = this.queryModelList(sql, paramObjs);
		if (modelList.size() > 0) {
			return modelList.get(0);
		}
		return null;
	}
}
